package com.cheyun.netsalev3.repository

import com.cheyun.netsalev3.bean.DaoDianDetailsParam
import com.cheyun.netsalev3.bean.FollowParam
import com.cheyun.netsalev3.bean.drive.ReserveInfo
import com.cheyun.netsalev3.utils.api.ApiCallback
import com.cheyun.netsalev3.utils.api.ApiClient
import com.cheyun.netsalev3.utils.api.ApiException
import com.cheyun.netsalev3.utils.api.BaseResp
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import kotlin.reflect.KFunction1

class CustomerStorePepository(var id: Int) {
    fun getdata(kFunction1: KFunction1<@ParameterName(name = "daoDianDetailsParam") DaoDianDetailsParam, Unit>) {
        ApiClient.getInstance().getDaoDianDetails(id)
                .subscribeOn(Schedulers.io())
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(object : ApiCallback<BaseResp<DaoDianDetailsParam>>() {
                    override fun onSuccess(t: BaseResp<DaoDianDetailsParam>) {
                        t.data?.apply {
                            kFunction1(this)
                        }
                    }

                    override fun onError(ex: ApiException) {

                    }


                })
    }

    fun getScanResult(phone:String,rid:String,kFunction1: (item: ReserveInfo) -> Unit){
        ApiClient.getInstance().getReserveInfo("",phone,"",rid)
                .subscribeOn(Schedulers.io())
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(object : ApiCallback<BaseResp<ReserveInfo>>() {
                    override fun onSuccess(t: BaseResp<ReserveInfo>) {
                        if (t.state == "y") {
                            kFunction1(t.data!!)
                        }
                    }
                    override fun onError(ex: ApiException) {

                    }


                })
    }

    /**
     *  客流接待-接待跟进
     */
    fun getfollow(id: Int, moth: (it: FollowParam) -> Unit) {
        ApiClient.getInstance().getfollow(id)
                .subscribeOn(Schedulers.io())
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(object : ApiCallback<BaseResp<FollowParam>>() {
                    override fun onSuccess(t: BaseResp<FollowParam>) {
                        t.data?.apply {
                            this.msg = t.msg ?: ""
                            moth(this)
                        }
                    }

                    override fun onError(ex: ApiException) {

                    }


                })
    }
}